<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>toRef</title>
  </head>
  <body>
    <div id="app"></div>
  </body>
  <script src="../lib/vue.global.js"></script>
  <script>
    const { ref, reactive, toRef } = Vue;

    Vue.createApp({
      setup() {
        // state 即为响应式对象
        // foo 以及 bar 即为 响应式对象上的一个属性
        const state = reactive({
          foo: 1,
          bar: 2,
        });

        // 基于响应式**对象**上的一个属性，创建一个对应的 ref
        const count = toRef(state, "foo");

        count.value++;
        console.log(state.foo); // 2
        console.log(count.value); // 2

        state.foo = 100;
        console.log(state.foo); // 100
        console.log(count.value); // 100

        return {};
      },
    }).mount("#app");
  </script>
</html>
